package com.example.archermind.myapplication;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.os.RemoteException;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class NetWorkActivity extends BaseActivity implements View.OnClickListener{

    @BindView(R.id.btn_registeNetworkStatusCallback)
    Button btnRegisteNetworkStatusCallback;
    @BindView(R.id.btn_unregisterNetworkStatusCallback)
    Button btnUnregisterNetworkStatusCallback;
    @BindView(R.id.tv_onMobile1NetworkStatusChange)
    TextView tvOnMobile1NetworkStatusChange;
    @BindView(R.id.tv_onMobile2NetworkStatusChange)
    TextView tvOnMobile2NetworkStatusChange;
    @BindView(R.id.tv_onWiFiNetworkStatusChange)
    TextView tvOnWiFiNetworkStatusChange;

    Handler mHandler = new Handler(){
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            Bundle bundle = msg.getData();
            int status = bundle.getInt("status");
            String type = bundle.getString("type");
            int intensity = bundle.getInt("intensity");
            switch (msg.what){
                case NETWORKSERVICECALLBACK + 0:
                    tvOnMobile1NetworkStatusChange.setText("OnMobile1NetworkStatusChange status:"+status+" type:"+type+" intensity:"+intensity);
                    break;
                case NETWORKSERVICECALLBACK + 1:
                    tvOnMobile2NetworkStatusChange.setText("tvOnMobile2NetworkStatusChange status:"+status+" type:"+type+" intensity:"+intensity);
                    break;
                case NETWORKSERVICECALLBACK + 2:
                    tvOnWiFiNetworkStatusChange.setText("tvOnWiFiNetworkStatusChange status:"+status+" type:"+type+" intensity:"+intensity);
                    break;
            }
        }
    };


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_net_work);
        unbinder = ButterKnife.bind(this);
        setHandler(mHandler);

    }

    @OnClick({
            R.id.btn_registeNetworkStatusCallback,R.id.btn_unregisterNetworkStatusCallback
    })
    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.btn_registeNetworkStatusCallback:
                try {
                    getNetworkService().registeNetworkStatusCallback(getNetworkServiceCallback());
                } catch (RemoteException e) {
                    e.printStackTrace();
                }
                break;
            case R.id.btn_unregisterNetworkStatusCallback:
                try {
                    getNetworkService().unregisterNetworkStatusCallback(getNetworkServiceCallback());
                } catch (RemoteException e) {
                    e.printStackTrace();
                }
                break;
        }

    }
}
